package com.zbkj.common.enums;

import com.zbkj.common.exception.CommonException;
import com.zbkj.common.model.project.EstimateFun;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @Auther:
 * @Date: 2024/10/8 20:40
 * @Description:
 */
public enum ProjectFunTypeEnum {
    //功能类型 枚举

    /**
     * 国标类型项目 功能类型对应值  ILF 10 EIF 7  EI 4 EO 5 EQ 4
     */
    ILF1("ILF","10",1),
    EIF1("EIF","7",1),
    EI1("EI","4",1),
    EO1("EO","5",1),
    EQ1("EQ","4",1),


    /**
     * 军标类型项目 功能类型 ILF 7 EIF 5  EI 4 EO 5 EQ 4
     */
    ILF2("ILF","7",2),
    EIF2("EIF","5",2),
    EI2("EI","4",2),
    EO2("EO","5",2),
    EQ2("EQ","4",2),
    ;

    @Getter
    private String funType;

    @Getter
    private String funPoints;

    @Getter
    private int ptype; //项目类型

    ProjectFunTypeEnum(String funType, String funPoints, int ptype) {
        this.funType = funType;
        this.funPoints = funPoints;
        this.ptype = ptype;
    }

    public static ProjectFunTypeEnum findTypeEnum(Integer ptype, String funType) {
        if(Objects.isNull(ptype) || StringUtils.isBlank(funType)) {
            return null;
        }
        for(ProjectFunTypeEnum fenum : ProjectFunTypeEnum.values()) {
            if(fenum.getPtype() == ptype && fenum.getFunType().equals(funType)) {
                return fenum;
            }
        }
        return null;
    }

    public static void findTypeSetAndCheck(Integer ptype, String funType, EstimateFun estimateFun) {
        ProjectFunTypeEnum funTypeEnum = findTypeEnum(ptype,funType);
        if(Objects.isNull(funTypeEnum)) {
            throw new CommonException("功能类型参数错误");
        }
        estimateFun.setFunPoints(funTypeEnum.getFunPoints());
    }

}
